#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# account_dialog.py 
#
#  Copyright (c) 2007 INdT (Instituto Nokia de Technologia)
#                2007 Kenneth Christiansen
#
#  Author: Kenneth Rohde Christiansen <kenneth.christiansen@gmail.com>
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation; either version 2 of the
#  License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
#  USA

import pygtk
pygtk.require("2.0")
import gtk
import pango
import gobject
import icon_theme

(
COMBO_CONFERENCE_SERVER_TEXT,
COMBO_CONFERENCE_SERVER_FIXED
) = range(2)


class JoinRoomWindow(gobject.GObject):

    def __init__(self):
        self.icon_theme = icon_theme.icon_theme_get_default()

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_position(gtk.WIN_POS_CENTER)
        self.window.set_title("Join Chat Room...")
        self.window.resize(200, 300)

        self.vbox1 = gtk.VBox(False, 0)
        self.window.add(self.vbox1)

        self.vbox2 = gtk.VBox(False, 0)
        self.vbox1.pack_start(self.vbox2, True, True, 0)

        self.table1 = gtk.Table(2, 2, False)
        self.vbox2.pack_start(self.table1, False, True, 0)
        self.table1.set_border_width(6)
        self.table1.set_row_spacings(3)
        self.table1.set_col_spacings(3)

        self.server_label = gtk.Label("Server:")
        self.table1.attach(self.server_label, 0, 1, 0, 1, \
            xoptions=gtk.FILL, xpadding=0, ypadding=0)
        self.server_label.set_size_request(72, -1)
        self.server_label.set_alignment(0, 0.5)

        self.room_label = gtk.Label("Room:")
        self.table1.attach(self.room_label, 0, 1, 1, 2, \
            xoptions=gtk.FILL, xpadding=0, ypadding=0)
        self.room_label.set_alignment(0, 0.5)

        self.conference_server_combo = gtk.ComboBox ()
        self.table1.attach(self.conference_server_combo, 1, 2, 0, 1, \
            xoptions=gtk.EXPAND|gtk.FILL, xpadding=0, ypadding=0)
        self.conference_server_store = gtk.ListStore(str, bool)

        cell_text = gtk.CellRendererText()
        cell_text.set_property('ellipsize', pango.ELLIPSIZE_END)
        self.conference_server_combo.pack_start(cell_text, True)
        self.conference_server_combo.add_attribute(cell_text, \
            "markup", COMBO_CONFERENCE_SERVER_TEXT)

        self.conference_server_combo.set_model(self.conference_server_store)

        self.conference_server_store.append(["conference.talk.google.com", False])
        self.conference_server_store.append(["Add new...", True])

        self.conference_server_combo.set_active(0)

        self.room_entry = gtk.Entry()
        self.table1.attach(self.room_entry, 1, 2, 1, 2, \
            xoptions=gtk.EXPAND|gtk.FILL, xpadding=0, ypadding=0)

        self.vbox3 = gtk.VBox(False, 0)
        self.vbox2.pack_start(self.vbox3, True, True, 0)

        self.alignment2 = gtk.Alignment(0.5, 0.5, 1, 1)
        self.vbox3.pack_start(self.alignment2, True, True, 0)
        self.alignment2.set_padding(0, 0, 6, 6)

        self.scrolledwindow = gtk.ScrolledWindow(None, None)
        self.alignment2.add(self.scrolledwindow)
        self.scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.scrolledwindow.set_shadow_type(gtk.SHADOW_IN)

        self.room_treeview = gtk.TreeView()
        self.scrolledwindow.add(self.room_treeview)
        self.room_treeview.set_headers_visible(False)

        self.hbox2 = gtk.HBox(False, 0)
        self.vbox1.pack_start(self.hbox2, False, True, 0)
        self.hbox2.set_border_width(6)

        self.info_image = gtk.Image()
        self.info_image.set_from_pixbuf(self.icon_theme.load_icon("gtk-info", 22, 0)) 

        self.hbox2.pack_start(self.info_image, True, True, 0)

        self.info_label = gtk.Label("Please wait while browsing for conference rooms...")
        self.hbox2.pack_start(self.info_label, False, False, 6)

        self.refresh_button = gtk.Button()
        self.hbox2.pack_start(self.refresh_button, False, False, 0)

        self.refresh_alignment = gtk.Alignment(0.5, 0.5, 0, 0)
        self.refresh_button.add (self.refresh_alignment)

        self.hbox3 = gtk.HBox(False, 2)
        self.refresh_alignment.add(self.hbox3)

        self.refresh_image = gtk.Image()
        self.refresh_image.set_from_pixbuf(self.icon_theme.load_icon("gtk-refresh", 22, 0))
        self.hbox3.pack_start(self.refresh_image, False, False, 0)

        self.refresh_label = gtk.Label("Refresh")
        self.hbox3.pack_start(self.refresh_label, False, False, 0)

        self.hseparator1 = gtk.HSeparator()
        self.vbox1.pack_start(self.hseparator1, False, True, 0)

        self.hbuttonbox1 = gtk.HButtonBox()
        self.vbox1.pack_start(self.hbuttonbox1, False, True, 0)
        self.hbuttonbox1.set_border_width(6)
        self.hbuttonbox1.set_layout(gtk.BUTTONBOX_END)
        self.hbuttonbox1.set_spacing(6)

        self.close_button = gtk.Button(stock="gtk-close")
        self.hbuttonbox1.add(self.close_button)

        self.join_button = gtk.Button()
        self.hbuttonbox1.add(self.join_button)

        self.alignment1 = gtk.Alignment(0.5, 0.5, 0, 0)
        self.join_button.add(self.alignment1)

        self.hbox1 = gtk.HBox(False, 2)
        self.alignment1.add(self.hbox1)

        self.apply_image = gtk.Image()
        self.apply_image.set_from_pixbuf(self.icon_theme.load_icon("gtk-apply", 22, 0))
        self.hbox1.pack_start(self.apply_image, False, False, 0)

        self.join_label = gtk.Label("Join")
        self.hbox1.pack_start(self.join_label, False, False, 0)

        self.window.show_all()

if __name__ == "__main__":
        window = JoinRoomWindow()
        gtk.main()

